/**
 * Created by chengming on 18/4/18.
 * version 1.0
 */
const BaseJsonAdapter = require('./base/BaseJsonAdapter');
const logger = require('../conf/logger');
const request = require('request-promise');
const urlTool = require('url');
const iconv = require("iconv-lite");
const report = require('../exception/ErrorReport');

class JsonAdapter extends BaseJsonAdapter{

	constructor(page, isTest){
		super(page, isTest);
	}

	async reqJson(){
		const body = await this.doRequest();
		let decodeBody = iconv.decode(body, this.encoding).toString().trim();
		if(decodeBody.startsWith("[") && decodeBody.endsWith("]")) {
			let data = {};
			data.data=JSON.parse(decodeBody);
			return data;
		}
		return JSON.parse(decodeBody);
	}
}

module.exports = JsonAdapter;